use utoipa::OpenApi;
use utoipa_axum::router::OpenApiRouter;
use utoipa_scalar::{Scalar, Servable as ScalarServable};
use utoipa_swagger_ui::SwaggerUi;

use core::prelude::ApiDoc;
use core::route::init_router as core_router;
use user::prelude::user_router;

#[tokio::main]
async fn main() {
    let (router, api) = OpenApiRouter::with_openapi(ApiDoc::openapi())
        .nest("/api/v1/core", core_router())
        .nest("/api/v1/user", user_router())
        .split_for_parts();

    let router = router
        .merge(SwaggerUi::new("/swagger-ui").url("/api-docs/openapi.json", api.clone()))
        .merge(Scalar::with_url("/scalar", api));

    let listener = tokio::net::TcpListener::bind("0.0.0.0:9527").await.unwrap();
    println!(
        "🚀 service successfully started on {}",
        listener.local_addr().unwrap()
    );
    axum::serve(listener, router.into_make_service())
        .await
        .unwrap();
}
